package com.boilerCloud.controller.work;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.boilerCloud.dataSource.LogAnnotation;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.sys.ReqResult;
import com.boilerCloud.dto.work.WorkOrder;
import com.boilerCloud.service.log.ILogService;
import com.boilerCloud.service.work.IWorkOrderService;


@RestController
@RequestMapping("/work/")
public class WorkOrderControler {
	private static final Logger log = LoggerFactory.getLogger(WorkOrderControler.class);
	@Resource
	private IWorkOrderService service;

	@Resource
	private ILogService logService;

	@RequestMapping(value = "workOrderList")
	public ModelAndView workOrderList() {
		return new ModelAndView("/views/after/workOrder.html");
	}

	
	

	/**
	 * 查询工单列表
	 * @param grade
	 * @param yema
	 * @param length
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "qryWorkOrderList", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult qryWorkOrderList(@ModelAttribute WorkOrder model ,
			@RequestParam(required = true) int yema,
			@RequestParam(required = true) int length,HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			
			HzlqswPage<WorkOrder> page = new HzlqswPage<WorkOrder>();
			page.setCurPage(yema);
			page.setPageSize(length);
			service.qryList(model,page);
			rst.setReturnObject(page);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("查询工单列表失败");
			log.error("查询工单列表异常",e);
			return rst;
		}
	}
	
	
	
	/**
	 * 新增工单
	 * @param device
	 * @param request
	 * @return
	 */
	@LogAnnotation("创建工单")
	@RequestMapping(value = "addWorkOrder", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult addWorkOrder(
			@ModelAttribute  WorkOrder model ,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			service.save(model);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("新增工单失败");
			log.error("新增工单异常",e);
			return rst;
		}
	}
	

	


	

}
